package star.servlet_2;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;


public class LoginServlet_10 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        String name = req.getParameter("name");
        String pwd = req.getParameter("password");
        String[] hobby = req.getParameterValues("hobby");
        System.out.println("==================================");
        System.out.println(name);
        System.out.println(pwd);
        System.out.println(Arrays.toString(hobby));
        System.out.println("==================================");

        //重定向,这个方法是从根目录
        //resp.sendRedirect("/Servlet_2_war/success.jsp");

        //通过请求转发,这个方法默认路径是从当前路径
        req.getRequestDispatcher("success.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
